home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cfgtex / cfgtex.txt next >
Text File  |  1992-09-21  |  2KB  |  81 lines

  1. 'CFGTEXT.TXT
  2. '  Routines to configure a text box for max length and upper/lower case translation
  3. '   and password hiding
  4. '
  5. '  These routines also appear to work fine with QEVB (Pioneer) controls
  6. '
  7. '  Jim McClure
  8. '  QED, Inc.
  9. '  9/16/92
  10. '  CSID = 76666,1303
  11. '   or jamcclure@qed.com from Internet
  12.  
  13.  
  14. '---------
  15. 'Win API Calls
  16. 'Put these in your Global module
  17. '---------
  18. Declare Function GetWindowLong& Lib "User" (ByVal hWd%, ByVal nIndex%)
  19. Declare Function SetWindowLong& Lib "User" (ByVal hWd%, ByVal nIndex%, ByVal dwNewLong&)
  20. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  21.  
  22. Global Const GWL_STYLE = -16
  23. Global Const ES_UPPERCASE = &H8&
  24. Global Const ES_LOWERCASE = &H10&
  25. Global Const ES_PASSWORD = &H20&
  26.  
  27. Global Const WM_USER = &H400
  28. Global Const EM_LIMITTEXT = WM_USER + 21
  29. Global Const EM_SETPASSWORDCHAR = WM_USER + 28
  30.  
  31.  
  32. '----------
  33. 'Get the VBHWND.ZIP file from Lib 1 and use the CTLHWND DLL in it
  34. '----------
  35. Declare Function ControlhWnd% Lib "CTLHWND" (Ctl as Control)
  36.  
  37.  
  38. '----------
  39. 'Routine to configure a text box
  40. 'Put this routine in a general module
  41. '----------
  42. Sub ConfigTextBox (t As Control, Style As Long, MaxLen As Integer)
  43.   Dim CtlStyles As Long, NewStyles As Long, Ok As Long
  44.   Dim tWnd As Integer
  45.  
  46.   'Get handle to text box control
  47.   tWnd = ControlhWnd(t)
  48.  
  49.   'Get current style settings
  50.   CtlStyles = GetWindowLong(tWnd, GWL_STYLE)
  51.  
  52.   'Add in new styles
  53.   'If you want to be able to "toggle" styles, use XOR here and send '1' bits for styles
  54.   NewStyles = CtlStyles Or Style
  55.  
  56.   'Set new style
  57.   CtlStyles = SetWindowLong(tWnd, GWL_STYLE, NewStyles)
  58.  
  59.   'Set type of password char
  60.   'Just use default '*', or could pass in a char for use
  61.   If (NewStyles And ES_PASSWORD) > 0 Then
  62.     Ok = SendMessage(tWnd, EM_SETPASSWORDCHAR, Asc("*"), 0&)
  63.   End If
  64.  
  65.   'Now set limit on length of text
  66.   '****THESE LINES WERE OMITTED ON THE INITIAL UPLOAD!****
  67.   If MaxLen > 0 Then
  68.     Ok = SendMessage(tWnd, EM_LIMITTEXT, MaxLen, 0)
  69.   End If
  70. End Sub
  71.  
  72.  
  73. '----------
  74. 'Sample calls to ConfigTextBox
  75. '----------
  76. Sub Form_Load()
  77.   ConfigTextBox Text1, ES_UPPERCASE, 10
  78.   ConfigTextBox Text2, ES_UPPERCASE Or ES_PASSWORD, 10
  79.   'etc...
  80. End Sub
  81.